﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Wwtfly.BBS.Framework.Caches;
using Wwtfly.Utility;
using Wwtfly.BBS.BackBLL.Plays;
namespace Wwtfly.BBS.ForeApplication.WebForm
{
    public partial class Lottery7LC_ZHFB : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GridViewBind();
                ColorBind();
                GridView1.Style["border-collapse"] = "";
            }
        }
        protected void GridViewBind()
        {

            DataTable dt = new DataTable();
            dt =LC7_ZHFB_Select(30, "", ""); //，默认显示30期
            if (dt == null || dt.Rows.Count < 1)
            {
                //Shove._Web.JavaScript.Alert(this.Page, "数据库里没有此彩种开奖号码信息！");
            }
            else
            {
                int i = dt.Rows.Count;
                tb1.Text = dt.Rows[0]["Isuse"].ToString();
                tb2.Text = dt.Rows[i - 1]["Isuse"].ToString();
            }

            GridView1.DataSource = dt;
            GridView1.DataBind();
        }
        public DataTable LC7_ZHFB_Select(int num, string str1, string str2)
        {
            DataTable dt = null;
            DataTable dt1 = null;

            dt = CacheHelper.Get("LC7_ZHFB_Select") as DataTable;

            if (dt == null || dt.Rows.Count < 1)
            {

                dt = PlaysBLL.Select_7LC_HMFBListWinber();

            }

            dt1 = dt.Clone();

            //通过期号来查询
            if (num == 0)
            {
                int i = str1.AsInt(0);
                int j = str2.AsInt(0);

                DataRow[] dr2 = dt.Select("Isuse>=" + i + " and  Isuse<=" + j);

                foreach (DataRow r in dr2)
                {
                    dt1.Rows.Add(r.ItemArray);
                }
            }

            //通过按纽选择查询多少期
            else
            {
                if (num >= dt.Rows.Count)
                {
                    num = dt.Rows.Count;
                }

                int ii = dt.Rows.Count;                           //总记录数
                int jj = ii - num;

                DataRow[] drr = dt.Select("id > " + jj + " and id <= " + ii);

                foreach (DataRow rr in drr)
                {
                    dt1.Rows.Add(rr.ItemArray);
                }
            }

            return dt1;
        }

        protected void btnTop30_Click(object sender, EventArgs e)
        {

            DataTable dt = new DataTable();
            dt = LC7_ZHFB_Select(30, "", ""); //，默认显示30期

            if (dt == null || dt.Rows.Count < 1)
            {
                //Shove._Web.JavaScript.Alert(this.Page, "数据库里没有此彩种开奖号码信息！");
            }
            else
            {
                int i = dt.Rows.Count;
                tb1.Text = dt.Rows[0]["Isuse"].ToString();
                tb2.Text = dt.Rows[i - 1]["Isuse"].ToString();
            }

            GridView1.DataSource = dt;
            GridView1.DataBind();
            ColorBind();
        }

        protected void btnTop50_Click(object sender, EventArgs e)
        {
 

            DataTable dt = new DataTable();
            dt =LC7_ZHFB_Select(50, "", ""); //，默认显示50期

            if (dt == null || dt.Rows.Count < 1)
            {
                //Shove._Web.JavaScript.Alert(this.Page, "数据库里没有此彩种开奖号码信息！");
            }
            else
            {
                int i = dt.Rows.Count;
                tb1.Text = dt.Rows[0]["Isuse"].ToString();
                tb2.Text = dt.Rows[i - 1]["Isuse"].ToString();
            }

            GridView1.DataSource = dt;
            GridView1.DataBind();
            ColorBind();
        }

        protected void btnTop100_Click(object sender, EventArgs e)
        {

            DataTable dt = new DataTable();
            dt = LC7_ZHFB_Select(100, "", ""); //，默认显示100期

            if (dt == null || dt.Rows.Count < 1)
            {
                //Shove._Web.JavaScript.Alert(this.Page, "数据库里没有此彩种开奖号码信息！");
            }
            else
            {
                int i = dt.Rows.Count;
                tb1.Text = dt.Rows[0]["Isuse"].ToString();
                tb2.Text = dt.Rows[i - 1]["Isuse"].ToString();
            }

            GridView1.DataSource = dt;
            GridView1.DataBind();
            ColorBind();
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            if (tb1.Text == "" || tb1.Text == null || tb2.Text == "" || tb2.Text == null)
            {
                Response.Write("<script> alert('请输入起止期数！');</script>");
               // Shove._Web.JavaScript.Alert(this.Page, "请输入起止期数！");
            }

            int i = tb1.Text.AsInt(0);
            int j = tb2.Text.AsInt(0);
            if (i > j)
            {
                Response.Write("<script> alert('起始期数输入有误，请查证在输入！');</script>");
                //Shove._Web.JavaScript.Alert(this.Page, "起始期数输入有误，请查证在输入！");
                return;
            }

            DataTable dt = null;

            dt =LC7_ZHFB_Select(0, tb1.Text.ToString(), tb2.Text.ToString());

            if (dt == null || dt.Rows.Count < 1)
            {
                //Shove._Web.JavaScript.Alert(this.Page, "数据库里没有此彩种开奖号码信息！");
            }
            else
            {
                int k = dt.Rows.Count;
                tb1.Text = dt.Rows[0]["Isuse"].ToString();
                tb2.Text = dt.Rows[k - 1]["Isuse"].ToString();
            }

            GridView1.DataSource = dt;
            GridView1.DataBind();
            ColorBind();
        }

        protected void ColorBind()
        {
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                for (int j = 33; j < 43; j++)
                {
                    if (GridView1.Rows[i].Cells[j].Text.AsInt(-1) == -1)
                    {
                        GridView1.Rows[i].Cells[j].Text = "&nbsp;";
                    }
                }

                if (GridView1.Rows[i].Cells[33].Text == "Blue|0")
                {
                    GridView1.Rows[i].Cells[33].Text = "0";
                    GridView1.Rows[i].Cells[33].ForeColor = System.Drawing.Color.FromArgb(000, 000, 255);
                }
                if (GridView1.Rows[i].Cells[33].Text == "Red|0")
                {
                    GridView1.Rows[i].Cells[33].Text = "0";
                    GridView1.Rows[i].Cells[33].ForeColor = System.Drawing.Color.FromArgb(255, 000, 000);
                }

                if (GridView1.Rows[i].Cells[34].Text == "Blue|1")
                {
                    GridView1.Rows[i].Cells[34].Text = "1";
                    GridView1.Rows[i].Cells[34].ForeColor = System.Drawing.Color.FromArgb(000, 000, 255);
                }
                if (GridView1.Rows[i].Cells[34].Text == "Red|1")
                {
                    GridView1.Rows[i].Cells[34].Text = "1";
                    GridView1.Rows[i].Cells[34].ForeColor = System.Drawing.Color.FromArgb(255, 000, 000);
                }

                if (GridView1.Rows[i].Cells[35].Text == "Blue|2")
                {
                    GridView1.Rows[i].Cells[35].Text = "2";
                    GridView1.Rows[i].Cells[35].ForeColor = System.Drawing.Color.FromArgb(000, 000, 255);
                }
                if (GridView1.Rows[i].Cells[35].Text == "Red|2")
                {
                    GridView1.Rows[i].Cells[35].Text = "2";
                    GridView1.Rows[i].Cells[35].ForeColor = System.Drawing.Color.FromArgb(255, 000, 000);
                }

                if (GridView1.Rows[i].Cells[36].Text == "Blue|3")
                {
                    GridView1.Rows[i].Cells[36].Text = "3";
                    GridView1.Rows[i].Cells[36].ForeColor = System.Drawing.Color.FromArgb(000, 000, 255);
                }
                if (GridView1.Rows[i].Cells[36].Text == "Red|3")
                {
                    GridView1.Rows[i].Cells[36].Text = "3";
                    GridView1.Rows[i].Cells[36].ForeColor = System.Drawing.Color.FromArgb(255, 000, 000);
                }
                if (GridView1.Rows[i].Cells[37].Text == "Blue|4")
                {
                    GridView1.Rows[i].Cells[37].Text = "4";
                    GridView1.Rows[i].Cells[37].ForeColor = System.Drawing.Color.FromArgb(000, 000, 255);
                }
                if (GridView1.Rows[i].Cells[37].Text == "Red|4")
                {
                    GridView1.Rows[i].Cells[37].Text = "4";
                    GridView1.Rows[i].Cells[37].ForeColor = System.Drawing.Color.FromArgb(255, 000, 000);
                }
                if (GridView1.Rows[i].Cells[38].Text == "Blue|5")
                {
                    GridView1.Rows[i].Cells[38].Text = "5";
                    GridView1.Rows[i].Cells[38].ForeColor = System.Drawing.Color.FromArgb(000, 000, 255);
                }
                if (GridView1.Rows[i].Cells[38].Text == "Red|5")
                {
                    GridView1.Rows[i].Cells[38].Text = "5";
                    GridView1.Rows[i].Cells[38].ForeColor = System.Drawing.Color.FromArgb(255, 000, 000);
                }
                if (GridView1.Rows[i].Cells[39].Text == "Blue|6")
                {
                    GridView1.Rows[i].Cells[39].Text = "6";
                    GridView1.Rows[i].Cells[39].ForeColor = System.Drawing.Color.FromArgb(000, 000, 255);
                }
                if (GridView1.Rows[i].Cells[39].Text == "Red|6")
                {
                    GridView1.Rows[i].Cells[39].Text = "6";
                    GridView1.Rows[i].Cells[39].ForeColor = System.Drawing.Color.FromArgb(255, 000, 000);
                }
                if (GridView1.Rows[i].Cells[40].Text == "Blue|7")
                {
                    GridView1.Rows[i].Cells[40].Text = "7";
                    GridView1.Rows[i].Cells[40].ForeColor = System.Drawing.Color.FromArgb(000, 000, 255);
                }
                if (GridView1.Rows[i].Cells[40].Text == "Red|7")
                {
                    GridView1.Rows[i].Cells[40].Text = "7";
                    GridView1.Rows[i].Cells[40].ForeColor = System.Drawing.Color.FromArgb(255, 000, 000);
                }
                if (GridView1.Rows[i].Cells[41].Text == "Blue|8")
                {
                    GridView1.Rows[i].Cells[41].Text = "8";
                    GridView1.Rows[i].Cells[41].ForeColor = System.Drawing.Color.FromArgb(000, 000, 255);
                }
                if (GridView1.Rows[i].Cells[41].Text == "Red|8")
                {
                    GridView1.Rows[i].Cells[41].Text = "8";
                    GridView1.Rows[i].Cells[41].ForeColor = System.Drawing.Color.FromArgb(255, 000, 000);
                }

                if (GridView1.Rows[i].Cells[42].Text == "Blue|9")
                {
                    GridView1.Rows[i].Cells[42].Text = "9";
                    GridView1.Rows[i].Cells[42].ForeColor = System.Drawing.Color.FromArgb(000, 000, 255);
                }
                if (GridView1.Rows[i].Cells[42].Text == "Red|9")
                {
                    GridView1.Rows[i].Cells[42].Text = "9";
                    GridView1.Rows[i].Cells[42].ForeColor = System.Drawing.Color.FromArgb(255, 000, 000);
                }

                for (int k = 1; k < 10; k++)
                {
                    if (GridView1.Rows[i].Cells[k].Text.AsInt(0) == 0)
                    {
                        GridView1.Rows[i].Cells[k].Text = "0" + k.ToString();
                        GridView1.Rows[i].Cells[k].ForeColor = System.Drawing.Color.FromArgb(255, 000, 000);
                        GridView1.Rows[i].Cells[k].Font.Bold = true;
                    }
                }
                for (int k = 10; k < 31; k++)
                {
                    if (GridView1.Rows[i].Cells[k].Text.AsInt(0) == 0)
                    {
                        GridView1.Rows[i].Cells[k].Text = k.ToString();
                        GridView1.Rows[i].Cells[k].ForeColor = System.Drawing.Color.FromArgb(255, 000, 000);
                        GridView1.Rows[i].Cells[k].Font.Bold = true;
                    }
                }

                //隐藏列
                for (int m = 1; m < 10; m++)
                {
                    if (GridView1.DataKeys[i].Value.ToString().AsInt(0) == m)
                    {
                        //string gv = GridView1.DataKeys[i].Value.ToString();
                        GridView1.Rows[i].Cells[m].Text = "0" + m.ToString();
                        GridView1.Rows[i].Cells[m].ForeColor = System.Drawing.Color.FromArgb(000, 000, 255);
                    }
                }
                for (int m = 10; m < 31; m++)
                {
                    if (GridView1.DataKeys[i].Value.ToString().AsInt(0) == m)
                    {
                        GridView1.Rows[i].Cells[m].Text = m.ToString();
                        GridView1.Rows[i].Cells[m].ForeColor = System.Drawing.Color.FromArgb(000, 000, 255);
                    }
                }
            }
        }

        protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                e.Row.SetRenderMethodDelegate(new RenderMethod(DrawGridFooter));
            }

            if (e.Row.RowType == DataControlRowType.Header)
            {
                e.Row.SetRenderMethodDelegate(new RenderMethod(DrawGridHeader));
            }
        }

        protected void DrawGridHeader(HtmlTextWriter output, Control ctl)
        {
            output.Write("<td rowspan='3'　 bgcolor='#e8f1f8'>期号</td>");
            output.Write("<td colspan='30'  bgcolor='#e8f1f8' height='18px'>号码分布</td>");
            output.Write("<td rowspan='3'　 bgcolor='#e8f1f8'>总和</td>");
            output.Write("<td rowspan='3'　 bgcolor='#e8f1f8'>奇偶比</td>");

            output.Write("<td colspan='10' rowspan='2'　 bgcolor='#e8f1f8'>个位分布</td>");

            output.Write("<tr  bgcolor='#e8f1f8' height='18px'>");
            output.Write("<td colspan='10'>一区</td>");
            output.Write("<td colspan='10'>二区</td>");
            output.Write("<td colspan='10'>三区</td>");


            output.Write("<tr  bgcolor='#f7f7f7'>");

            for (int i = 1; i < 10; i++)
            {
                output.Write("<td bgcolor='#f7f7f7' height='18px'>");
                output.Write(0 + i.ToString() + "</td>");
            }
            for (int i = 10; i < 31; i++)
            {
                output.Write("<td bgcolor='#f7f7f7'>");
                output.Write(i.ToString() + "</td>");
            }
            for (int i = 0; i < 10; i++)
            {
                output.Write("<td bgcolor='#f7f7f7' height='18px'>");
                output.Write(i.ToString() + "</td>");
            }
        }

        protected void DrawGridFooter(HtmlTextWriter output, Control ctl)
        {
            output.Write("<td Height='18px'>预选1</td>");

            for (int i = 1; i < 10; i++)
            {
                output.Write("<td bgcolor='#FFFFFF' onClick=Style(this,'#ff0000','#FFFFFF') style='color:#FFFFFF; cursor:pointer;' ><strong>");
                output.Write(0 + i.ToString() + "</strong></span></td>");
            }

            for (int i = 10; i < 31; i++)
            {
                output.Write("<td bgcolor='#FFFFFF' onClick=Style(this,'#ff0000','#FFFFFF') style='color:#FFFFFF; cursor:pointer;' ><strong>");
                output.Write(i.ToString() + "</strong></td>");
            }

            output.Write("<td>&nbsp;</td>");
            output.Write("<td>&nbsp;</td>");

            for (int i = 0; i < 10; i++)
            {
                output.Write("<td bgcolor='#FFFFFF' onClick=Style(this,'#000000','#FFFFFF') style='color:#FFFFFF; cursor:pointer;' ><strong>");
                output.Write(i.ToString() + "</strong></span></td>");
            }

            output.Write("<tr  style='cursor:pointer;'>");
            output.Write("<td  Height='18px'>预选2</td>");

            for (int i = 1; i < 10; i++)
            {
                output.Write("<td bgcolor='#FFFFFF' onClick=Style(this,'#ff0000','#FFFFFF') style='color:#FFFFFF; cursor:pointer;' ><strong>");
                output.Write(0 + i.ToString() + "</strong></span></td>");
            }

            for (int i = 10; i < 31; i++)
            {
                output.Write("<td bgcolor='#FFFFFF' onClick=Style(this,'#ff0000','#FFFFFF') style='color:#FFFFFF;' ><strong>");
                output.Write(i.ToString() + "</strong></td>");
            }

            output.Write("<td>&nbsp;</td>");
            output.Write("<td>&nbsp;</td>");

            for (int i = 0; i < 10; i++)
            {
                output.Write("<td bgcolor='#FFFFFF' onClick=Style(this,'#000000','#FFFFFF') style='color:#FFFFFF;' ><strong>");
                output.Write(i.ToString() + "</strong></span></td>");
            }

            output.Write("<tr  style='cursor:pointer;'>");
            output.Write("<td  Height='18px'>预选3</td>");

            for (int i = 1; i < 10; i++)
            {
                output.Write("<td bgcolor='#FFFFFF' onClick=Style(this,'#ff0000','#FFFFFF') style='color:#FFFFFF;' ><strong>");
                output.Write(0 + i.ToString() + "</strong></span></td>");
            }

            for (int i = 10; i < 31; i++)
            {
                output.Write("<td bgcolor='#FFFFFF' onClick=Style(this,'#ff0000','#FFFFFF') style='color:#FFFFFF;' ><strong>");
                output.Write(i.ToString() + "</strong></td>");
            }

            output.Write("<td>&nbsp;</td>");
            output.Write("<td>&nbsp;</td>");

            for (int i = 0; i < 10; i++)
            {
                output.Write("<td bgcolor='#FFFFFF' onClick=Style(this,'#000000','#FFFFFF') style='color:#FFFFFF;' ><strong>");
                output.Write(i.ToString() + "</strong></span></td>");
            }

            output.Write("<tr  bgcolor='#e8f1f8'>");
            output.Write("<td rowspan='3'　 bgcolor='#e8f1f8'>期号</td>");
            for (int i = 1; i < 10; i++)
            {
                output.Write("<td bgcolor='#f7f7f7' height='18px'>");
                output.Write(0 + i.ToString() + "</td>");
            }

            for (int i = 10; i < 31; i++)
            {
                output.Write("<td bgcolor='#f7f7f7'>");
                output.Write(i.ToString() + "</td>");
            }
            output.Write("<td rowspan='3'　 bgcolor='#e8f1f8'>总和</td>");
            output.Write("<td rowspan='3'　 bgcolor='#e8f1f8'>奇偶比</td>");
            for (int i = 0; i < 10; i++)
            {
                output.Write("<td bgcolor='#f7f7f7' height='18px'>");
                output.Write(i.ToString() + "</td>");
            }

            output.Write("<tr  bgcolor='#e8f1f8' height='18px'>");
            output.Write("<td colspan='10'>一区</td>");
            output.Write("<td colspan='10'>二区</td>");
            output.Write("<td colspan='10'>三区</td>");
            output.Write("<td colspan='10' rowspan='2'　 >个位分布</td>");

            output.Write("<tr >");
            output.Write("<td colspan='30' bgcolor='#e8f1f8'>号码分布</td>");
        }
    }
}